// components/popCard/index.js
import chatService from "../../apis/chat.js";

const innerAudioContext = wx.createInnerAudioContext({
	useWebAudioImplement: true,
})//音频播放器
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    popShow:Boolean,
    cardInfo:Object
  },

  /**
   * 组件的初始数据
   */
  data: {
  },

  /**
   * 组件的方法列表
   */
  methods: {
    close(){
      this.triggerEvent('closePop')
    },
    onAddTap(e){
      const { phrase } = e.currentTarget.dataset
      this.triggerEvent('addToWorkbook',phrase)
    },
    onDelTap(e){
      const { phrase } = e.currentTarget.dataset
      this.triggerEvent('DelFromWorkbook',phrase)
    },
    playPhrase(e){
      const { phrase , type } = e.currentTarget.dataset
      chatService.text_to_voice(
        {
          "content": phrase, // 转换的文字
          "phonetic": type // 发音类型：ph_am/ph_en，TODO: 本期不区分
        }
      ).then(res=>{
        console.log('playPhrase==========',res.data)
        innerAudioContext.src ='data:audio/x-wav;base64,' +  res.data.base64_voice_data
        innerAudioContext.play();
      })
    },
  }
})